﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IceStart.View;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;

namespace IceStart.Core
{
    public class Coordinates
    {
        public static Dictionary<IMagnet, Point> MagnetTable = new Dictionary<IMagnet, Point>();

        public static bool RegisterPosition(IMagnet Magnet)
        {
            if (Magnet is FileMagnet FileMagnet)
            {
                FileMagnet.nowLeft = Math.Round(FileMagnet.nowLeft / 60) * 60;
                FileMagnet.nowTop = Math.Round(FileMagnet.nowTop / 60) * 60;
                if (FileMagnet.nowTop < 0) FileMagnet.nowTop = 0;
                if (FileMagnet.nowLeft < 0) FileMagnet.nowLeft = 0;
                Canvas.SetLeft(FileMagnet, FileMagnet.nowLeft);
                Canvas.SetTop(FileMagnet, FileMagnet.nowTop);

                if (MagnetTable.ContainsKey(Magnet))
                    MagnetTable.Remove(Magnet);
                MagnetTable.Add(FileMagnet, new Point(FileMagnet.nowLeft / 60, FileMagnet.nowTop / 60));
            }
            else if (Magnet is ImageMagnetTie ImageMagnetTie)
            {
            }
            return true;
        }

        public static bool RegisterPosition(IMagnet Magnet, Point MouseRelativePos)
        {
            if (Magnet is FileMagnet FileMagnet)
            {
                if (FileMagnet.MagnetTie.ButtonSize == AbstractMagnetTie.Size.Large)
                {
                    FileMagnet.SetPosition(MouseRelativePos.Y - 120, MouseRelativePos.X - 120);
                    RegisterPosition(FileMagnet);
                }
                if (FileMagnet.MagnetTie.ButtonSize == AbstractMagnetTie.Size.Medium)
                {
                    FileMagnet.SetPosition(MouseRelativePos.Y - 60, MouseRelativePos.X - 60);
                    RegisterPosition(FileMagnet);
                }
                if (FileMagnet.MagnetTie.ButtonSize == AbstractMagnetTie.Size.Small)
                {
                    FileMagnet.SetPosition(MouseRelativePos.Y - 30, MouseRelativePos.X - 30);
                    var a = Mouse.GetPosition(((MainWindow)Application.Current.MainWindow).MainMagnet_Container);
                    RegisterPosition(FileMagnet);
                }
            }
            else if (Magnet is ImageMagnetTie ImageMagnetTie)
            {
            }
            return true;
        }
    }
}